import { defineStore } from 'pinia'
import { removeToken } from '@renderer/utils/auth'
import { ref } from 'vue'

export const UserStore = defineStore('user', () => {
  // data
  const token = ref<string | null>('123456')

  // actions
  // 登录方法
  function Login(loginForm: void | PromiseLike<void>) {
    return new Promise<void>((resolve) => {
      resolve(loginForm)
    })
  }

  // 退出方法
  function LogOut() {
    return new Promise<void>((resolve) => {
      resolve()
    })
  }
  // 重置token
  const resetToken = () => {
    return new Promise<void>((resolve) => {
      token.value = ''
      removeToken()
      resolve()
    })
  }
  // 返回需要导出的内容
  return { token, Login, LogOut, resetToken }
})
export default UserStore
